﻿<%@ Page Title="" Language="C#" MasterPageFile="~/ShopCart/ShopCartMaster.Master" AutoEventWireup="true" CodeBehind="ShoppingCart.aspx.cs" Inherits="ZLCMS.Web.ShopCart.ShoppingCart" %>
<%@ Register src="UC/UC_HotProduct.ascx" tagname="UC_HotProduct" tagprefix="uc1" %>
<%@ Import Namespace="ZLCMS.Business.Util" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!--wrapper start-->
<div id="main">
	<div class="regist_top">
      <!--logo start-->
      <div class="regist_logo"><a href="/default.aspx"><img src="/MemberUser/images/logo.png" width="147" height="69" /></a></div>
      <!--logo end-->
      <div class="regist_yous step1">&nbsp;</div>
      <div class="clear"></div>
    </div>

    <div class="cart_box">
    	<ul class="title">
        	<li><input name="" type="checkbox" value=""  id="ckb_all" onchange="selAll(this)" />全选</li>
            <li class="pro">产品</li>
            <li>数量</li>
            <li>单价</li>
            <li>小计</li>
            <li>操作</li>
            <div class="clear"></div>
        </ul>
           <asp:Repeater ID="rpt_Product" runat="server">
        <ItemTemplate>
        <ul class="pro_detail" id="ul_<%# Eval("ProductSkuCode") %>" name="ul_pro" >
        	<li><input 
                  name="ckb_sel" 
                code='<%# Eval("ProductSkuCode") %>' 
                productno='<%# Eval("ProductNo") %>'  
                productskucode='<%# Eval("ProductSkuCode") %>'  
                items='<%# Eval("ParamCode") %>'
                  onclick="GetSum()" type="checkbox" value="" /></li>
            <li class="pro">
            <a  href='/product/ProductDetail.aspx?no=<%# Eval("ProductNo") %>' >
            <img src='<%# FileKit.FirstImgPathThumb(Eval("ImageUrl") as string) %>' width="59" height="59" />
            </a>
            	<div class="pro_text"><%# Eval("ProductName") %><%# GetSkuItemHtml(Eval("ParamCode") == null ? "" :Convert.ToString(  Eval("ParamCode")))%></div>
                 <input type="hidden" name="unitPrice" value='<%# Eval("UnitPrice")%>'/>
            </li>
            <li class="numn">
            <a href="javascript:void(0);" class="jian" onclick="reduceQuantity(this,'<%# Eval("ProductSkuCode") %>')">-</a>
            <input id='txt_Count_<%# Eval("ProductSkuCode") %>'  
            name="numBox" type="text" class="shul"
            type="text" value='<%# Eval("ProductCount") %>' 
            onblur="GetTotalPrice(this,'<%# Eval("ProductSkuCode") %>')"  />
            <a  href="javascript:void(0);" onclick="addQuantity(this,'<%# Eval("ProductSkuCode") %>')">+</a>
            <div class="clear"></div></li>
            <li>￥<%#string.Format("{0:0.##}", Eval("UnitPrice"))%></li>
            <li>￥<font name="simgleTotalPrice" id='font_total_price_<%# Eval("ProductSkuCode") %>'><%#string.Format("{0:0.##}", Eval("TotalPrice"))%></font></li>
            <li><a href="#"  onclick="DelCart('<%# Eval("ProductSkuCode") %>')"  >删除</a></li>
            <div class="clear"></div>
        </ul>
        </ItemTemplate>
    </asp:Repeater>
    </div>
    
    <div class="jiesuanlan">
    	<div class="p_left">
        	<%--<input name=""  type="checkbox" value=""  id="ckb_all" onchange="selAll(this)" />全选<a href="#">删除</a>--%><a href="/Shop/Index.aspx" class="button">继续购物</a>
        </div>
        <div class="p_right"> <form id="form1" action="/ShopCart/ShoppingCartConfirm.aspx?kind=normal" method="post" >
        	共<span id="span_product_count">2</span>件商品&nbsp;&nbsp;应付总额<label>(不含运费)</label>：<strong>￥<font id="font_sum"><%=string.Format("{0:0.##}", totalPrice)%></font></strong>
            &nbsp;&nbsp;
               <input type="hidden" id="hdn_codes" name="products"/>
            <a  href="javascript:void(0);"  onclick="Account()"  >去结算</a>
            </form>
        </div>
        <div class="clear"></div>
    </div>
    
    <uc1:UC_HotProduct ID="UC_HotProduct1" runat="server" />
</div>
<!--wrapper end-->
<script type="text/javascript">


    //数量-1
    function reduceQuantity(ct, skuCode) {
        $("#txt_Count_" + skuCode).val(parseInt($("#txt_Count_" + skuCode).val()) - 1);
        if ($("#txt_Count_" + skuCode).val() == "0") {
            $("#txt_Count_" + skuCode).val("1");
        }
        GetTotalPrice($("#txt_Count_" + skuCode), skuCode);
        GetSum();
    }
    //数量+1
    function addQuantity(ct, skuCode) {
        $("#txt_Count_" + skuCode).val(parseInt($("#txt_Count_" + skuCode).val()) + 1);
        if ($("#txt_Count_" + skuCode).val() == "100") {
            $("#txt_Count_" + skuCode).val("99");
        }
        GetTotalPrice($("#txt_Count_" + skuCode), skuCode);
        GetSum();
    }
    //获取合计金额
    function GetTotalPrice(ct, skuCode) {
        var count = $(ct).val().trim();
        //文本框限输入数字 
        if (!isNaN(count) && count > 0 && count < 999 && count) {
            //获取合计
            $(ct).ExecuteCommand({
                successCallBack: function (result) {
                    $("#txt_Count_" + skuCode).val(count);
                    //修改合计金额
                    $("#font_total_price_" + skuCode).html(result);
                    //获取总额
                    GetSum();
                },
                errorCallback: function (errorCode, msg) {
                    alert(msg);
                }
            }, 'UpdateShoppingCartProductQuantity', { Kind: 'normal', ProductSkuCode: skuCode, Num: parseInt(count) });

        } else {
            alert("请输入正确的数量!");
            $("#txt_Count_" + skuCode).val(1);
            count = 1;
            GetTotalPrice(ct, skuCode);
        }
    }
    //获取总额
    function GetSum() {
        //修改总金额
        var isAllChecked = true;
        var uls = $("ul[name=ul_pro]");
        //   var numList = $("input[name=numBox]");
        var sum = 0;
        var proCount = 0;
        $(uls).each(function () {
            if ($(this).find("input[name=ckb_sel]").first().is(":checked")) {
                sum += parseFloat($(this).find("font[name=simgleTotalPrice] ").first().html());
                proCount += parseInt($(this).find("input[name=numBox] ").first().val());
            }
            else {
                isAllChecked = false;
            }
        });
        $("#span_product_count").html(proCount);
        $("#font_sum").html(sum);
        $("#ckb_all").prop("checked", isAllChecked);
    }
    //删除操作
    function DelCart(code) {
        if (confirm("您确认要删除吗？")) {
            $("#ul_" + code).ExecuteCommand({
                successCallBack: function (result) {
                    alert('操作成功');
                    $("#ul_" + code).remove();
//                    if ($("li[name=li_pro]").length == 0) {
//                        location.href = "/Wap/Shop/EmptyShoppingCart.aspx";
//                    }
                    //当购物车为空
                    GetSum();
                },
                errorCallback: function (errorCode, msg) {
                    alert(msg);
                }
            }, 'RemoveShoppingCartProduct', { ProductSkuCode: code });
        };
    }
    //结算
    function Account() {
        var products = [];
        var cbxlist = $("input[name=ckb_sel]");
        cbxlist.each(function () {
            $this = $(this);
            var product = {};
            if ($this.is(":checked")) {
                product.ProductSkuCode = $this.attr("code");
                product.ProductNo = $this.attr("productno");
                product.Quantity = $("#txt_Count_" + $this.attr("code")).val();
                product.Items = $this.attr("items");

                products.push(product);
            }
        });
        $("#hdn_codes").val(JSON.stringify(products));
        if (products.length > 0) {
            //调整到提交订单页面
            //$("#form1").attr("method","post");
            $("#form1").submit();
        }
        else {
            alert('请选择需要结算的商品');
        }
    }
    function selAll(ct) {
        $this = $(ct);
      //  alert($this.prop("checked"));
        if ($this.prop("checked")==true) {
            $("input[name=ckb_sel]").each(function () {
                $(this).prop("checked", true);
            });
        }
        else {
            $("input[name=ckb_sel]").each(function () {
                $(this).prop("checked", false);
            });
        }
        GetSum();
    }
    //页面初始化时全选产品
    $(function () {
        //设置产品为全选
        $("#ckb_all").attr("checked", true);
        selAll($("#ckb_all"));
    });  
  </script>
</asp:Content>
